package derbyclnt;

import static java.lang.System.out;
import static java.lang.System.err;

public class Logger {
	
	public enum Level {
		ERROR,
		WARNING,
		INFO,
		DEBUG
	}
	
	private static Logger s_logger = null;
	private Logger() {}
	
	private void write(Level level, String message) {
		if (level == Level.ERROR)
		{
			err.println(message);
			new Throwable().printStackTrace();
		}
		else
		{
			Object els[] = Thread.currentThread().getStackTrace();
			Object el = els.length > 4 ? els[4] : null;
			out.println((el != null ? el + " : " : "") + message);
		}
	}

	synchronized public static void log (Level level, String message) {
		if (s_logger == null)
			s_logger = new Logger();
		
		s_logger.write(level, message);
	}
	
	public static void loge(String error) { log(Level.ERROR, error); }
	public static void logw(String warning) { log(Level.WARNING, warning); }
	public static void logi(String info) { log(Level.INFO, info); }
	public static void logd(String debug) { log(Level.DEBUG, debug); }
	
}
